#include <stdio.h>
#include <unistd.h>
 
int main(int argc, char *argv[]) {
    int para;
    const char *optstring = "abc:d::"; // 有三个选项-abc，其中c选项后有冒号，所以后面必须有参数,d是选参
	for(int i=0;i<argc;i++)
		printf("argv[%d] is %s,the value is %p \n",i,argv[i],argv[i]);
    while ((para = getopt(argc, argv, optstring)) != -1) {
        switch (para) {
            case 'a':
                printf("parameter opt is a, oprarg is: %s the value of optarg is%p, the value of optind is%d\n", optarg,optarg,optind);
                break;
            case 'b':
                printf("parameter opt is b, oprarg is: %s the value of optarg is%p, the value of optind is%d\n", optarg,optarg,optind);
                break;
            case 'c':
		printf("parameter opt is c, oprarg is: %s the value of optarg is%p, the value of optind is%d\n", optarg,optarg,optind);
                break;
            case 'd':
		printf("parameter opt is d, oprarg is: %s the value of optarg is%p, the value of optind is%d\n", optarg,optarg,optind);
                break;
            case '?':
                printf("error optopt: %c\n", optopt);
                printf("error opterr: %d\n", opterr);
                break;
        }
    }
    return 0;
}
